#
#        Python GUI - Controls - Swing
#

#TODO: needs a control.lines() method

from GControls import Control as GControl
from JHacks import *
from java.awt.event import ActionListener

class _j_ActionCallback(ActionListener):
    def __init__(self,target):
        self.target=target
    def actionPerformed(self,e):
        self.target.trigger()

class Control(GControl):
    
    pass

#Java uses HTML in its labels
def to_html(text,align):
    #align="left"
    if '\n' not in text and align=="left": return text
    
    if align=="centre": align="center"
    text=text.replace('\n','<br>')
    return "<html><div align=\"%s\">%s</div></html>"%(align,text)
    #return "<html>%s</html>"%text

def from_html(text):
    if not text.startswith('<html>'): return text
    return text[text.index('">')+2:-13].replace('<br>','\n')